XAPK Installer.apk(点击下载) / Slider.java


package com.gc.materialdesign.views;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.nineoldandroids.view.ViewHelper;

public class Slider extends c.d.a.e.b {
    public int g = Color.parseColor("#4CAF50");
    public b h;
    public d i;
    public boolean j = false;
    public boolean k = false;
    public int l = 0;
    public int m = 100;
    public int n = 0;
    public e o;
    public boolean p = false;

    public class a implements Runnable {

        /* renamed from: c  reason: collision with root package name */
        public final /* synthetic */ int f2104c;

        public a(int i) {
            this.f2104c = i;
        }

        public void run() {
            Slider.this.setValue(this.f2104c);
        }
    }

    public class b extends View {

        /* renamed from: c  reason: collision with root package name */
        public float f2106c;

        /* renamed from: e  reason: collision with root package name */
        public float f2107e;
        public float f;

        public b(Context context) {
            super(context);
            setBackgroundResource(c.d.a.a.background_switch_ball_uncheck);
        }

        public void a() {
            Slider slider = Slider.this;
            if (slider.l != slider.n) {
                setBackgroundResource(c.d.a.a.background_checkbox);
                ((GradientDrawable) ((LayerDrawable) getBackground()).findDrawableByLayerId(c.d.a.b.shape_bacground)).setColor(Slider.this.g);
                return;
            }
            setBackgroundResource(c.d.a.a.background_switch_ball_uncheck);
        }
    }

    public class c extends RelativeLayout {

        /* renamed from: c  reason: collision with root package name */
        public float f2108c;

        /* renamed from: e  reason: collision with root package name */
        public float f2109e = 0.0f;
        public float f = 0.0f;
        public float g = 0.0f;
        public float h = 0.0f;
        public boolean i = true;
        public boolean j = false;

        public c(Context context) {
            super(context);
            setBackgroundColor(getResources().getColor(17170445));
        }

        public void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (!this.j) {
                RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) Slider.this.i.f2111e.getLayoutParams();
                float f2 = this.h;
                layoutParams.height = ((int) f2) * 2;
                layoutParams.width = ((int) f2) * 2;
                Slider.this.i.f2111e.setLayoutParams(layoutParams);
            }
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            paint.setColor(Slider.this.g);
            if (this.i) {
                if (this.f2109e == 0.0f) {
                    this.f2109e = this.g + (this.h * 2.0f);
                }
                this.f2109e -= (float) c.d.a.d.a.a(6.0f, getResources());
                this.f += (float) c.d.a.d.a.a(2.0f, getResources());
            }
            canvas.drawCircle(ViewHelper.getX(Slider.this.h) + ((float) c.d.a.d.a.a((View) Slider.this.h.getParent())) + ((float) (Slider.this.h.getWidth() / 2)), this.f2109e, this.f, paint);
            if (this.i && this.f >= this.h) {
                this.i = false;
            }
            if (!this.i) {
                Slider slider = Slider.this;
                ViewHelper.setX(slider.i.f2111e, ((ViewHelper.getX(slider.h) + ((float) c.d.a.d.a.a((View) Slider.this.h.getParent()))) + ((float) (Slider.this.h.getWidth() / 2))) - this.f);
                ViewHelper.setY(Slider.this.i.f2111e, this.f2109e - this.f);
                Slider.this.i.f2111e.setText(Slider.this.l + "");
            }
            invalidate();
        }
    }

    public class d extends Dialog {

        /* renamed from: c  reason: collision with root package name */
        public c f2110c;

        /* renamed from: e  reason: collision with root package name */
        public TextView f2111e;

        public d(Context context) {
            super(context, 16973839);
        }

        public void dismiss() {
            super.dismiss();
            c cVar = this.f2110c;
            cVar.f2109e = 0.0f;
            cVar.f = 0.0f;
            cVar.i = true;
        }

        public void onBackPressed() {
        }

        public void onCreate(Bundle bundle) {
            requestWindowFeature(1);
            super.onCreate(bundle);
            setContentView(c.d.a.c.number_indicator_spinner);
            setCanceledOnTouchOutside(false);
            RelativeLayout relativeLayout = (RelativeLayout) findViewById(c.d.a.b.number_indicator_spinner_content);
            this.f2110c = new c(getContext());
            relativeLayout.addView(this.f2110c);
            this.f2111e = new TextView(getContext());
            this.f2111e.setTextColor(-1);
            this.f2111e.setGravity(17);
            relativeLayout.addView(this.f2111e);
            this.f2110c.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
        }
    }

    public interface e {
        void a(int i);
    }

    public Slider(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        setAttributes(attributeSet);
    }

    public final void a() {
        ViewHelper.setX(this.h, (float) ((getHeight() / 2) - (this.h.getWidth() / 2)));
        b bVar = this.h;
        bVar.f2106c = ViewHelper.getX(bVar);
        this.h.f2107e = (float) ((getWidth() - (getHeight() / 2)) - (this.h.getWidth() / 2));
        this.h.f = (float) ((getWidth() / 2) - (this.h.getWidth() / 2));
        this.p = true;
    }

    public int getMax() {
        return this.m;
    }

    public int getMin() {
        return this.n;
    }

    public e getOnValueChangedListener() {
        return this.o;
    }

    public int getValue() {
        return this.l;
    }

    public void invalidate() {
        b bVar = this.h;
        if (bVar != null) {
            bVar.invalidate();
        }
        super.invalidate();
    }

    @Override // c.d.a.e.b
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (!this.p) {
            a();
        }
        if (this.l == this.n) {
            Bitmap createBitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas2 = new Canvas(createBitmap);
            Paint paint = new Paint();
            paint.setColor(Color.parseColor("#B0B0B0"));
            paint.setStrokeWidth((float) c.d.a.d.a.a(2.0f, getResources()));
            canvas2.drawLine((float) (getHeight() / 2), (float) (getHeight() / 2), (float) (getWidth() - (getHeight() / 2)), (float) (getHeight() / 2), paint);
            Paint paint2 = new Paint();
            paint2.setColor(getResources().getColor(17170445));
            paint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
            canvas2.drawCircle(ViewHelper.getX(this.h) + ((float) (this.h.getWidth() / 2)), ViewHelper.getY(this.h) + ((float) (this.h.getHeight() / 2)), (float) (this.h.getWidth() / 2), paint2);
            canvas.drawBitmap(createBitmap, 0.0f, 0.0f, new Paint());
        } else {
            Paint paint3 = new Paint();
            paint3.setColor(Color.parseColor("#B0B0B0"));
            paint3.setStrokeWidth((float) c.d.a.d.a.a(2.0f, getResources()));
            canvas.drawLine((float) (getHeight() / 2), (float) (getHeight() / 2), (float) (getWidth() - (getHeight() / 2)), (float) (getHeight() / 2), paint3);
            paint3.setColor(this.g);
            b bVar = this.h;
            float f = bVar.f2107e - bVar.f2106c;
            int i2 = this.m;
            int i3 = this.n;
            canvas.drawLine((float) (getHeight() / 2), (float) (getHeight() / 2), (((float) (this.l - i3)) * (f / ((float) (i2 - i3)))) + ((float) (getHeight() / 2)), (float) (getHeight() / 2), paint3);
        }
        if (this.k && !this.j) {
            Paint paint4 = new Paint();
            paint4.setColor(this.g);
            paint4.setAntiAlias(true);
            canvas.drawCircle(ViewHelper.getX(this.h) + ((float) (this.h.getWidth() / 2)), (float) (getHeight() / 2), (float) (getHeight() / 3), paint4);
        }
        invalidate();
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        int i2;
        if (isEnabled()) {
            if (motionEvent.getAction() == 0 || motionEvent.getAction() == 2) {
                d dVar = this.i;
                if (dVar != null && !dVar.isShowing()) {
                    this.i.show();
                }
                if (motionEvent.getX() > ((float) getWidth()) || motionEvent.getX() < 0.0f) {
                    this.k = false;
                    d dVar2 = this.i;
                    if (dVar2 != null) {
                        dVar2.dismiss();
                    }
                } else {
                    this.k = true;
                    b bVar = this.h;
                    float f = (bVar.f2107e - bVar.f2106c) / ((float) (this.m - this.n));
                    if (motionEvent.getX() > this.h.f2107e) {
                        i2 = this.m;
                    } else if (motionEvent.getX() < this.h.f2106c) {
                        i2 = this.n;
                    } else {
                        i2 = this.n + ((int) ((motionEvent.getX() - this.h.f2106c) / f));
                    }
                    if (this.l != i2) {
                        this.l = i2;
                        e eVar = this.o;
                        if (eVar != null) {
                            eVar.a(i2);
                        }
                    }
                    float x = motionEvent.getX();
                    float f2 = this.h.f2106c;
                    if (x < f2) {
                        x = f2;
                    }
                    float f3 = this.h.f2107e;
                    if (x > f3) {
                        x = f3;
                    }
                    ViewHelper.setX(this.h, x);
                    this.h.a();
                    d dVar3 = this.i;
                    if (dVar3 != null) {
                        c cVar = dVar3.f2110c;
                        cVar.f2108c = x;
                        cVar.g = (float) (c.d.a.d.a.b(this) - (getHeight() / 2));
                        this.i.f2110c.h = (float) (getHeight() / 2);
                        this.i.f2111e.setText("");
                    }
                }
            } else if (motionEvent.getAction() == 1 || motionEvent.getAction() == 3) {
                d dVar4 = this.i;
                if (dVar4 != null) {
                    dVar4.dismiss();
                }
                this.k = false;
            }
        }
        return true;
    }

    public void setAttributes(AttributeSet attributeSet) {
        setBackgroundResource(c.d.a.a.background_transparent);
        setMinimumHeight(c.d.a.d.a.a(48.0f, getResources()));
        setMinimumWidth(c.d.a.d.a.a(80.0f, getResources()));
        int attributeResourceValue = attributeSet.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "background", -1);
        if (attributeResourceValue != -1) {
            setBackgroundColor(getResources().getColor(attributeResourceValue));
        } else {
            int attributeIntValue = attributeSet.getAttributeIntValue("http://schemas.android.com/apk/res/android", "background", -1);
            if (attributeIntValue != -1) {
                setBackgroundColor(attributeIntValue);
            }
        }
        this.j = attributeSet.getAttributeBooleanValue("http://schemas.android.com/apk/res-auto", "showNumberIndicator", false);
        this.n = attributeSet.getAttributeIntValue("http://schemas.android.com/apk/res-auto", "min", 0);
        this.m = attributeSet.getAttributeIntValue("http://schemas.android.com/apk/res-auto", "max", 0);
        this.l = attributeSet.getAttributeIntValue("http://schemas.android.com/apk/res-auto", "value", this.n);
        this.h = new b(getContext());
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(c.d.a.d.a.a(20.0f, getResources()), c.d.a.d.a.a(20.0f, getResources()));
        layoutParams.addRule(15, -1);
        this.h.setLayoutParams(layoutParams);
        addView(this.h);
        if (this.j) {
            this.i = new d(getContext());
        }
    }

    public void setBackgroundColor(int i2) {
        this.g = i2;
        if (isEnabled()) {
            this.f1678e = this.g;
        }
    }

    public void setMax(int i2) {
        this.m = i2;
    }

    public void setMin(int i2) {
        this.n = i2;
    }

    public void setOnValueChangedListener(e eVar) {
        this.o = eVar;
    }

    public void setShowNumberIndicator(boolean z) {
        this.j = z;
        this.i = z ? new d(getContext()) : null;
    }

    public void setValue(int i2) {
        if (!this.p) {
            post(new a(i2));
            return;
        }
        this.l = i2;
        b bVar = this.h;
        ViewHelper.setX(bVar, ((((float) i2) * ((bVar.f2107e - bVar.f2106c) / ((float) this.m))) + ((float) (getHeight() / 2))) - ((float) (this.h.getWidth() / 2)));
        this.h.a();
    }
}